import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/pages/contact/ContactItem.dart';

import 'ContactsModel.dart';

class ContactItemWithPY extends StatefulWidget {

  final EdgeInsets padding;
  final ContactListData? data;

  const ContactItemWithPY(this.data, {
    Key? key, this.padding = EdgeInsets.zero,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _ContactItemWithPYState();
  }
}

class _ContactItemWithPYState extends BaseState<ContactItemWithPY> {

  @override
  Widget build(BuildContext context) {
    print('build...');
    return
      Padding(padding: widget.padding, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
        Text(widget.data?.initial ?? '', style: TS(15, C.gray333, fontWeight: FontWeight.bold)),
        H(7),
        ...buildList()
      ]));
  }

  List<Widget> buildList() {
    List<Widget> result = [];
    for (int i = 0; i < (widget.data?.data?.length ?? 0); i++) {

      result.add(ContactItem(widget.data?.data?[i]));
      result.add(DD(paddingLeft: 48));
    }
    return result;
  }
}